<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //reduce 

    //参数：prev：上次调用函数的返回值   item：当前元素  index：当前元素索引 arr：被遍历的数组 initValue:函数迭代的初始值
   //array.reduce(function(prev, item, index, arr), initValue)

    //作用：数组累加求和  累计值+每一项，起始值
    const arr = [1,2,3,4,5]
    const re= arr.reduce((prev,item)=>prev+item,0)
    console.log(re);

  </script>
</body>
</html>